package com.goods.action.goods;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;

import com.common.action.BaseAction;
import com.common.domain.GoodsVo;
import com.common.domain.UserVo;
import com.common.page.PaginationQueryDto;
import com.common.param.GoodsParam;
import com.common.param.UserParam;
import com.common.query.QueryResult;
import com.goods.service.SearchGoodsService;
import com.goods.service.SearchGoodsWithLuceneService;
import com.system.service.SystemService;

/**
 * 系统管理(用户管理、权限管理) action lph
 */
@SuppressWarnings("unused")
@Controller("goods")
public class GoodsAction extends BaseAction {
	private static final long serialVersionUID = 8676645302222211858L;
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	private static final String LIST_PAGE_GOODS_NAME = "goodslist";
	private GoodsParam goodsParam = new GoodsParam();
	private PaginationQueryDto<GoodsVo> searchDto = new PaginationQueryDto<GoodsVo>();

	private GoodsVo vo = new GoodsVo();
	
	public GoodsVo getVo() {
		return vo;
	}

	public void setVo(GoodsVo vo) {
		this.vo = vo;
	}

	@Resource
	private SearchGoodsWithLuceneService searchGoodsWithLuceneService;
	
	public String queryGoods() {
		if (null == request) {
			request = ServletActionContext.getRequest();
		}
		searchDto.init(request);
		
		goodsParam.setStart(searchDto.getOffset());
		goodsParam.setOffset(searchDto.getMaxRow());
		goodsParam.setEntity(vo);

		try {
			QueryResult<GoodsVo> qryResult = searchGoodsWithLuceneService.queryGoodsWithLucene(goodsParam);
			if (qryResult != null) {
				searchDto.setResultList(qryResult.getResult());
				searchDto.setTotalRecords(Long.valueOf(qryResult.getTotal()));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.setAttribute("_pagination", searchDto.getPagination());
		return LIST_PAGE_GOODS_NAME;
	}

	public GoodsParam getGoodsParam() {
		return goodsParam;
	}

	public void setGoodsParam(GoodsParam goodsParam) {
		this.goodsParam = goodsParam;
	}

	public PaginationQueryDto<GoodsVo> getSearchDto() {
		return searchDto;
	}

	public void setSearchDto(PaginationQueryDto<GoodsVo> searchDto) {
		this.searchDto = searchDto;
	}

	/**
	 * 用户增加
	 * 
	 * @return
	 */
	public String addUser() {
		return "list";
	}

	/**
	 * 用户修改
	 * 
	 * @return
	 */
	public String modifyUser() {
		return "list";
	}

}
